<?php
/*
 * @Author: your name
 * @Date: 2020-12-24 16:22:44
 * @LastEditTime: 2020-12-28 10:02:39
 * @LastEditors: Please set LastEditors
 * @Description: 资产组
 * @FilePath: /special/application/adminapiv3/controller/platform_manage/ServerHostGroupController.php
 */

namespace app\adminapiv3\controller\platform_manage;


use app\adminapiv3\controller\BaseController;
use app\adminapiv3\model\ServerHostGroupModel;
use think\Request;

class ServerHostGroupController extends BaseController
{
    /**
     * 列表
    */
    public function index(Request $request){
        $serach = $request->only([
            'name','description','check_code','create_time'
        ],'get');

        $model = new ServerHostGroupModel();
        $list = $model->getList($serach);
        return $this->jsonOutPut($list);
    }

    /**
     * 添加
    */
    public function add(Request $request){
        $model = new ServerHostGroupModel();
        if($request->isPost()){
            //授权 至少勾选一个模块 模块的数量至少为1
            $param = $request->only([
                'name','description','module'
            ],'post');
            $this->validate($param,'ServerHostGroup.add');
            $res = $model->addGroup($param);
            return $this->jsonOutPut($res);
        }
        if($request->isGet()){
            //查询回显数据
            $res = $model->getInfo([],'add');
            return $this->jsonOutPut($res);
        }
    }

    /**
     * 修改
    */
    public function modify(Request $request){
        $model = new ServerHostGroupModel();
        if($request->isPost()){
            //授权 至少勾选一个模块 模块的数量至少为1
            $param = $request->only([
                'id','name','description','module'
            ],'post');

            $this->validate($param,'ServerHostGroup.modify');
            $res = $model->modifyGroup($param);
            return $this->jsonOutPut($res);
        }
        if($request->isGet()){
            $param = $request->only(['id'],'get');
            $this->validate($param,'ServerHostGroup.modify_detail');
            //查询回显数据
            $res = $model->getInfo($param,'modify');
            return $this->jsonOutPut($res);
        }
    }

    /**
     * 删除
    */
    public function del(Request $request){
        $param = $request->only(['id'],'post');
        $this->validate($param,'ServerHostGroup.del');
        $model = new ServerHostGroupModel();
        $res = $model->delGroup($param['id']);
        return $this->jsonOutPut($res);
    }


}